package com.ejd.web.vo.genl;

import java.util.List;




import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.ejd.service.IBasemetalService;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Basemetal;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.SpringBeanConstants;

@ManagedBean(name="existBasemetal")
@SessionScoped
public class ExistBasemetalBean implements java.io.Serializable {

	private SelectItem[] basemetalItems;

	public SelectItem[] getBasemetalItems() {
		return basemetalItems;
	}

	public void setBasemetalItems(SelectItem[] basemetalItems) {
		this.basemetalItems = basemetalItems;
	}
	public ExistBasemetalBean() {
		
		IBasemetalService<Basemetal,Long> basemetalService = (IBasemetalService<Basemetal,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.BASEMETAL_SERVICE_BEAN_NAME);
		basemetalService.setEntityClass(Basemetal.class);
		basemetalService.setPKClass(Long.class);
		List<Basemetal> basemetals = basemetalService.getAll();
		SelectItem[] tempBasemetalItems = new SelectItem[basemetals.size()];
		if (null != basemetals && !(basemetals.isEmpty())) {
			for (int i=0; i< tempBasemetalItems.length; i++) {
				Basemetal basemetal = (Basemetal) basemetals.get(i);
				String basemetalNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,basemetal.getBasemetalName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempBasemetalItems[i] = new SelectItem(basemetal.getBasemetalCode(),basemetalNameN18);
			}
		}
		this.setBasemetalItems(tempBasemetalItems);
	}
}
